package com.framework.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.framework.dao.OrAppAdvDao;
import com.framework.entity.or.OrAppAdv;
import com.framework.entity.sys.SysAgent;
import com.framework.page.PageUtils;
import com.framework.page.Query;
import com.framework.service.AgentService;
import com.framework.service.OrAppAdvService;
import com.framework.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service("orAppAdvService")
public class OrAppAdvServiceImpl extends ServiceImpl<OrAppAdvDao, OrAppAdv> implements OrAppAdvService {
    @Autowired
    private AgentService agentService;


    @Override
    public List<OrAppAdv> getIndexAdv(String token) {
        SysAgent agent = agentService.queryAgentByToken(token);
        List<OrAppAdv> list = baseMapper.selectList(new EntityWrapper<OrAppAdv>()
                .eq("dept_id", agent.getDeptId())
                .eq("show_adv", 1)
                .orderBy("sort", true)
        );
        return list;
    }
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Long deptId = Long.valueOf(params.get("deptId").toString());
        Page<OrAppAdv> page = selectPage(new Query<OrAppAdv>(params).getPage(), new EntityWrapper<OrAppAdv>().eq("dept_id", deptId));

        return new PageUtils(page);
    }

    @Override
    public void save(OrAppAdv orAppAdv) {
        orAppAdv.setCreateDate(new Date());
        baseMapper.insert(orAppAdv);
    }
}
